<?php

include('../../include/functions.inc.php');
include('../../include/inputbuilder.inc.php');

if (!isEmpty(getParam('operation'))) {
    switch (getParam('operation')) {
        case 's':
            save($db);
            break;
        case 'u':
            update($db);
            break;
        case 'd':
            delete($db);
            break;
    }
}

function save($db) {
    $db->query_insert('cllg_courses_catalog', array(
        'CODE' => sqlValue(getParam('CODE'), 'int'),
        'NAME' => sqlValue(getParam('NAME'), 'text'),
        'LONG_DESCRIPTION' => sqlValue(getParam('LONG_DESCRIPTION'), 'text'),
        'DURATION_MONTHS' => sqlValue(getParam('DURATION_MONTHS'), 'int'),
        'FK_ENTITY' => sqlValue(getParam('FK_ENTITY'), 'int'),
        'CREATED_BY' => sqlValue(getParam('CREATED_BY'), 'text'),
        'CREATED' => sqlValue(getParam('CREATED'), 'date')));
    echo 'SAVED';
}

function update($db) {
    $db->query_update('cllg_courses_catalog', array(
        'NAME' => sqlValue(getParam('NAME'), 'text'),
        'LONG_DESCRIPTION' => sqlValue(getParam('LONG_DESCRIPTION'), 'text'),
        'DURATION_MONTHS' => sqlValue(getParam('DURATION_MONTHS'), 'int'),
        'FK_ENTITY' => sqlValue(getParam('FK_ENTITY'), 'int'))
            , 'CODE=' . sqlValue(getParam('CODE'), 'int'));
    echo 'UPDATED';
}

function delete($db) {
    $db->query_delete('cllg_courses_catalog', 'CODE=' . sqlValue(getParam('CODE'), 'int'));
    echo 'DELETED';
}

?>